//
//  AddNewPeopelVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/17.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "AddNewPeopelVC.h"
#import "SignUpVC.h"
@interface AddNewPeopelVC ()

@end

@implementation AddNewPeopelVC
{
    UITextField *_nameTF;
    UITextField *_IDCardTF;
    UITextField *_phoneTF;
    
    NSMutableArray *_arr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"添加新用户";
    _arr = [[NSMutableArray alloc]init];
    [self initViewWithNewPeo];
}
- (void)initViewWithNewPeo{
    UILabel *nameLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 80, 100, 35)];
    nameLb.text = @"真实姓名：";
    [self.view addSubview:nameLb];
    _nameTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 80, KScreenWidth - 140, 35)];
    _nameTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    _nameTF.leftViewMode = UITextFieldViewModeAlways;
    _nameTF.placeholder = @"请输入真实姓名";
    _nameTF.clearButtonMode = UITextFieldViewModeAlways;
    _nameTF.layer.borderWidth = 1;
    _nameTF.layer.borderColor = Theme_Color.CGColor;
    _nameTF.layer.cornerRadius = 5;
    [self.view addSubview:_nameTF];
    
    UILabel *IDCardLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 130, 100, 35)];
    IDCardLb.text = @"身份证号：";
    [self.view addSubview:IDCardLb];
    _IDCardTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 130, KScreenWidth - 140, 35)];
    _IDCardTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    _IDCardTF.leftViewMode = UITextFieldViewModeAlways;
    _IDCardTF.placeholder = @"请输入真实身份证号";
    _IDCardTF.clearButtonMode = UITextFieldViewModeAlways;
    _IDCardTF.layer.borderWidth = 1;
    _IDCardTF.layer.borderColor = Theme_Color.CGColor;
    _IDCardTF.layer.cornerRadius = 5;
    [self.view addSubview:_IDCardTF];
    
    UILabel *phoneLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 180, 100, 35)];
    phoneLb.text = @"手机号：";
    [self.view addSubview:phoneLb];
    _phoneTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 180, KScreenWidth - 140, 35)];
    _phoneTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    _phoneTF.leftViewMode = UITextFieldViewModeAlways;
    _phoneTF.placeholder = @"请输入真实手机号";
    _phoneTF.clearButtonMode = UITextFieldViewModeAlways;
    _phoneTF.layer.borderWidth = 1;
    _phoneTF.layer.borderColor = Theme_Color.CGColor;
    _phoneTF.layer.cornerRadius = 5;
    [self.view addSubview:_phoneTF];
    
    UIButton *doneBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 330, KScreenWidth-20, 40)];
    doneBtn.tintColor = [UIColor whiteColor];
    [doneBtn setTitle:@"完成" forState:UIControlStateNormal];
    doneBtn.backgroundColor = Theme_Color;
    doneBtn.layer.cornerRadius = 5;
    [doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:doneBtn];

}
- (void)doneBtnAction{
    if (![_nameTF.text isEqualToString:@""]&&[_phoneTF.text isValidateMobileAndTel]&&[_IDCardTF.text isValidateIdentityCard]) {
        NSDictionary *dic=@{@"name":_nameTF.text,
                            @"phone":_phoneTF.text,
                            @"card":_IDCardTF.text
                            };
        [_arr addObject:dic];
        NSLog(@"%@",_arr);
        [CacheData setArr:_arr];
        [SVProgressHUD showSuccessWithStatus:@"添加完成，你还可以继续添加"];
    }else{
        if (![_phoneTF.text isValidateMobileAndTel]) {
            [SVProgressHUD showErrorWithStatus:@"手机号不正确"];
        }
        if (![_IDCardTF.text isValidateIdentityCard]) {
            [SVProgressHUD showErrorWithStatus:@"身份证号不正确"];
        }
        if ([_nameTF.text isEqualToString:@""]) {
            [SVProgressHUD showErrorWithStatus:@"请输入姓名"];
        }
        
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
